package com.living.player.ui.recently.adapter;

import android.view.ViewGroup;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.living.R;
import com.living.utils.ImgLoadUtils;
import com.md.network.api.Album;
import com.md.network.api.Audio;

import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/***
 * 下载适配器
 */
public class RecentlyAlbumAdapter extends BaseQuickAdapter<Album, BaseViewHolder> {

    boolean isInEdite = false;
    private Map<String, Album> mapSel = new ConcurrentHashMap<>();

    public RecentlyAlbumAdapter(boolean isInEdite, Map<String, Album> mapSel) {
        super(R.layout.item_recently_album);
        this.isInEdite = isInEdite;
        this.mapSel = mapSel;
    }

    public RecentlyAlbumAdapter() {
        super(R.layout.item_recently_album);
    }

    @NotNull
    @Override
    protected BaseViewHolder onCreateDefViewHolder(@NotNull ViewGroup parent, int viewType) {
        BaseViewHolder holder = super.onCreateDefViewHolder(parent, viewType);
        return holder;
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, Album model) {
        ImageView iv_recently_album_icon = holder.getView(R.id.iv_recently_album_icon);
        ImgLoadUtils.disPlayRound(getContext().getApplicationContext(), iv_recently_album_icon, model.getCoverUrl());
        holder.setText(R.id.tv_recently_album_name, model.getName());
        holder.setText(R.id.tv_recently_album_desc, model.getCount() + "首 来自 " + model.getAuthor());

        if (isInEdite) {
            holder.setGone(R.id.iv_recently_album_select, false);
            holder.setGone(R.id.task_action_more, true);
            if (mapSel.containsKey(model.getId())) {
                holder.setImageResource(R.id.iv_recently_album_select, R.drawable.icon_download_selected);
            } else {
                holder.setImageResource(R.id.iv_recently_album_select, R.drawable.icon_download_select);
            }
        } else {
            holder.setGone(R.id.iv_recently_album_select, true);
            holder.setGone(R.id.task_action_more, false);
        }

    }


}
